#include "menu.h"
unsigned char menu_principal()
{

    unsigned char tmp=0;
    Local_Code_Clear();
    clr_lcd();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"ELEGIR MODO:");
    print(0,2,"1 AUTOMATICO");
    print(0,3,"2 MANUAL");
    print(0,4,"3 PC       ");
    Cursor_turn();
    tmp=key_read();
    send_data(tmp);
    sleep(1000);
    return tmp;
}
double menu_factor_galga()
{
    unsigned char tmp[6];
    unsigned char i =0;
    unsigned char dat;
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"Factor de Galga:");
    print(0,4,"A=OK    B=CLEAR");
    print(0,2,"KF= ");
    for(i=0; i<6; i++)tmp[i]=0;
    i=0;
    while(i<6)
    {
        dat=key_read();
        if(dat=='B')
        {
            print(0,2,"                ");
            print(0,2,"KF= ");
            i=0;
            continue;
        }
        if(dat=='A')break;//enter
        if(dat=='*')dat='.';
        if(dat=='#')continue;
        if(dat=='C')continue;
        if(dat=='D')continue;
        tmp[i]=dat;
        send_data(dat);
        i++;

    }
    return atof(tmp); //convierto tmp a doble y lo retorno

}
unsigned char menu_manual()
{
//unsigned char tmp=0;
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"MODO MANUAL:");
    sleep(2000);
    return 0;
}
unsigned char menu_pc()
{
//unsigned char tmp=0;
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"MODO PC:");
    sleep(2000);
    return 0;
}
unsigned char menu_error()
{

    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    Cursor_OFF();
    print(2,1,"OPCION:");
    print(2,2,"INCORRECTA");
    sleep(2000);
    return 0;
}
double menu_factor_puente()
{
    unsigned char tmp[6];
    unsigned char i =0;
    unsigned char dat;
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"Factor de Puente");
    print(0,4,"A=OK    B=CLEAR");
    print(0,2,"KP= ");
    for(i=0; i<6; i++)tmp[i]=0;
    i=0;
    while(i<6)
    {
        dat=key_read();
        if(dat=='B')
        {
            print(0,2,"                ");
            print(0,2,"KF= ");
            i=0;
            continue;
        }
        if(dat=='A')break;//enter
        if(dat=='*')dat='.';
        if(dat=='#')continue;
        if(dat=='C')continue;
        if(dat=='D')continue;
        tmp[i]=dat;
        send_data(dat);
        i++;

    }
    return atof(tmp); //convierto tmp a doble y lo retorno

}

unsigned int menu_tm()
{
    unsigned char tmp;
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"Tiempo de Muestreo");
    print(0,2,"A=0.5 s B=1.0 s");
    print(0,3,"C=1.5 s D=2.0 s");
    print(0,4,"*=2.5 s ");
    tmp=key_read();
    send_data(tmp);
    switch(tmp)
    {

    case 'A':
        return 500;
    case 'B':
        return 1000;
    case 'C':
        return 1500;
    case 'D':
        return 2000;
    case '*':
        return 2500;
    default :
        return 0;
    }



}

unsigned int numero_de_muestras()
{
    unsigned char tmp[6];
    unsigned char i =0;
    unsigned char dat;
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"# De Muestras:");
    print(0,4,"A=OK    B=CLEAR");
    print(0,2,"#= ");
    for(i=0; i<6; i++)tmp[i]=0;
    i=0;
    while(i<6)
    {
        dat=key_read();
        if(dat=='B')
        {
            print(0,2,"                ");
            print(0,2,"#= ");
            i=0;
            continue;
        }
        if(dat=='A')break;//enter
        if(dat=='*')continue;
        if(dat=='#')continue;
        if(dat=='C')continue;
        if(dat=='D')continue;
        tmp[i]=dat;
        send_data(dat);
        i++;

    }
    return atoi(tmp); //convierto tmp a entero y lo retorno



}

unsigned char menu_getName()
{

    unsigned char i=0;
    unsigned char data;
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    print(0,1,"FILE SD: 8 CHAR");
    //print(0,2,"MAX: 8 CHAR:");
    print(0,4,"#=OK    *=CLEAR");
    print(0,2,"NAME: ");
    for(i=0; i<13; i++)
        fileName[i] = 0x00;
    i=0;
    while(i<8)
    {
        data = key_read();
        if(data == '#') break;
        if(data == '*')
        {
            print(0,3,"NAME: ");
            i=0;
        }
        send_data(data);
        fileName[i++] = data;

        if(i>7)break;

    }
    if(i>7)
    {
        print(0,3,"Nombre largo..");
        sleep(1000);
        return 1;
    }

    fileName[i++]='.';
    fileName[i++]='c';
    fileName[i++]='v';
    fileName[i++]='s';


    return 0;

}

void menu_SD_Detect(){
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    Cursor_OFF();
    print(0,1,"SD ERROR");
    print(0,2,"INTRODUCIR SD");
    print(0,3,"REINICIAR");
}

void menu_FAT32_Detect(){
    clr_lcd();
    Local_Code_Clear();
    Graphic_ON();
    ClearGraphics();
    Draw_Rectangle(0,0,64,128);
    Graphic_OFF();
    Cursor_OFF();
    print(2,1,"FAT32 ERROR");
    print(0,2,"FORMATEAR SD");
    print(0,3,"SISTEMA FAT32");
    print(2,4,"REINICIAR");


}
